from datetime import datetime
from routes import db
# from sqlalchemy import Integer, String, BLOB, TIMESTAMP,Column, DECIMAL,String
# from sqlalchemy.orm import Mapped, mapped_column


class GepParameter(db.Model):
    __tablename__ = 'gep_parameters'
    id = db.Column(db.Integer, primary_key=True)
    year = db.Column(db.Integer, nullable=False)
    gepCity = db.Column(db.String(50), nullable=False)
    gepDistrict = db.Column(db.String(50), nullable=False)
    gepTown = db.Column(db.String(50), nullable=False)
    inAgricultural = db.Column(db.Float, nullable=True)
    inForestry = db.Column(db.Float, nullable=True)
    inAnimalHusbandry = db.Column(db.Float, nullable=True)
    inFishery = db.Column(db.Float, nullable=True)
    inEcologicalEnergy = db.Column(db.Float, nullable=True)
    inElectricityPrice = db.Column(db.Float, nullable=True)
    inWaterResources = db.Column(db.Float, nullable=True)
    inLocalWaterPrice = db.Column(db.Float, nullable=True)
    inProtectedArea = db.Column(db.Float, nullable=True)
    inProtectedCost = db.Column(db.Float, nullable=True)
    inNoiseReductionAmount = db.Column(db.Float, nullable=True)
    inNoiseCost = db.Column(db.Float, nullable=True)
    inTourismRevenue = db.Column(db.Float, nullable=True)
    inHousingAreaPerCapita = db.Column(db.Float, nullable=True)
    inHousePrice = db.Column(db.Float, nullable=True)
    inHotelRooms = db.Column(db.Float, nullable=True)
    inRoomPrice = db.Column(db.Float, nullable=True)
    inUrbanPopulation = db.Column(db.Float, nullable=True)
    inOccupancyRate = db.Column(db.Float, nullable=True)
    inLeisureTime = db.Column(db.Float, nullable=True)
    inAverageIncome = db.Column(db.Float, nullable=True)
    creator = db.Column(db.String(50), nullable=False)
    updater = db.Column(db.String(50), nullable=False)
    created_at = db.Column(db.DateTime, default=datetime.utcnow)
    updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)

    def to_dict(self):
        return {
            'id': self.id,
            'year': self.year,
            'gepCity': self.gepCity,
            'gepDistrict': self.gepDistrict,
            'gepTown': self.gepTown,
            'inAgricultural': self.inAgricultural,
            'inForestry': self.inForestry,
            'inAnimalHusbandry': self.inAnimalHusbandry,
            'inFishery': self.inFishery,
            'inEcologicalEnergy': self.inEcologicalEnergy,
            'inElectricityPrice': self.inElectricityPrice,
            'inWaterResources': self.inWaterResources,
            'inLocalWaterPrice': self.inLocalWaterPrice,
            'inProtectedArea': self.inProtectedArea,
            'inProtectedCost': self.inProtectedCost,
            'inNoiseReductionAmount': self.inNoiseReductionAmount,
            'inNoiseCost': self.inNoiseCost,
            'inTourismRevenue': self.inTourismRevenue,
            'inHousingAreaPerCapita': self.inHousingAreaPerCapita,
            'inHousePrice': self.inHousePrice,
            'inHotelRooms': self.inHotelRooms,
            'inRoomPrice': self.inRoomPrice,
            'inUrbanPopulation': self.inUrbanPopulation,
            'inOccupancyRate': self.inOccupancyRate,
            'inLeisureTime': self.inLeisureTime,
            'inAverageIncome': self.inAverageIncome,
            'creator': self.creator,
            'updater': self.updater,
            'created_at': self.created_at.isoformat() if self.created_at else None,
            'updated_at': self.updated_at.isoformat() if self.updated_at else None
        }

class GepResult(db.Model):
    __tablename__ = 'gep_results'
    id = db.Column(db.Integer, primary_key=True)
    year = db.Column(db.Integer, nullable=False)
    gepCity = db.Column(db.String(50), nullable=False)
    gepDistrict = db.Column(db.String(50), nullable=False)
    gepTown = db.Column(db.String(50), nullable=False)
    gepResult = db.Column(db.Float, nullable=True)
    materialSupplyValue = db.Column(db.Float, nullable=True)
    cleanEnergyValue = db.Column(db.Float, nullable=True)
    waterResourcesValue = db.Column(db.Float, nullable=True)
    tourismHealthValue = db.Column(db.Float, nullable=True)
    leisureRecreationValue = db.Column(db.Float, nullable=True)
    landscapeAppreciationValue = db.Column(db.Float, nullable=True)
    creator = db.Column(db.String(50), nullable=False)
    updater = db.Column(db.String(50), nullable=False)
    created_at = db.Column(db.DateTime, default=datetime.utcnow)
    updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)

    def to_dict(self):
        return {
            'id': self.id,
            'year': self.year,
            'gepCity': self.gepCity,
            'gepDistrict': self.gepDistrict,
            'gepTown': self.gepTown,
            'gepResult': self.gepResult,
            'cleanEnergyValue': self.cleanEnergyValue,
            'waterResourcesValue': self.waterResourcesValue,
            'tourismHealthValue': self.tourismHealthValue,
            'leisureRecreationValue': self.leisureRecreationValue,
            'landscapeAppreciationValue': self.landscapeAppreciationValue,
            'creator': self.creator,
            'updater': self.updater,
            'created_at': self.created_at.isoformat(),
            'updated_at': self.updated_at.isoformat()
        }